package com.ruoyi.hospital.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.hospital.domain.YlLabel;
import com.ruoyi.hospital.service.IYlLabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 标签信息Controller
 * 
 * @author ruoyi
 * @date 2022-02-16
 */
@RestController
@RequestMapping("/label")
public class YlLabelController extends BaseController
{
    @Autowired
    private IYlLabelService ylLabelService;

    /**
     * 查询标签信息列表
     */
    @RequiresPermissions("hospital:label:list")
    @GetMapping("/list")
    public TableDataInfo list(YlLabel ylLabel)
    {
        startPage();
        List<YlLabel> list = ylLabelService.selectYlLabelList(ylLabel);
        return getDataTable(list);
    }

    /**
     * 导出标签信息列表
     */
    @RequiresPermissions("hospital:label:export")
    @Log(title = "标签信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YlLabel ylLabel)
    {
        List<YlLabel> list = ylLabelService.selectYlLabelList(ylLabel);
        ExcelUtil<YlLabel> util = new ExcelUtil<YlLabel>(YlLabel.class);
        util.exportExcel(response, list, "标签信息数据");
    }

    /**
     * 获取标签信息详细信息
     */
    @RequiresPermissions("hospital:label:query")
    @GetMapping(value = "/{labelId}")
    public AjaxResult getInfo(@PathVariable("labelId") Long labelId)
    {
        return AjaxResult.success(ylLabelService.selectYlLabelByLabelId(labelId));
    }

    /**
     * 新增标签信息
     */
    @RequiresPermissions("hospital:label:add")
    @Log(title = "标签信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YlLabel ylLabel)
    {
        return toAjax(ylLabelService.insertYlLabel(ylLabel));
    }

    /**
     * 修改标签信息
     */
    @RequiresPermissions("hospital:label:edit")
    @Log(title = "标签信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YlLabel ylLabel)
    {
        return toAjax(ylLabelService.updateYlLabel(ylLabel));
    }

    /**
     * 删除标签信息
     */
    @RequiresPermissions("hospital:label:remove")
    @Log(title = "标签信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{labelIds}")
    public AjaxResult remove(@PathVariable Long[] labelIds)
    {
        return toAjax(ylLabelService.deleteYlLabelByLabelIds(labelIds));
    }
}
